/**
 * class Invoice
 */
package com.data.documents;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.StringTokenizer;

/**
 * Class Invoice. This class holds invoice info.
 * 
 * @author Elizabeth
 * @version 1.1
 */
public class Invoice extends UserDocument{
	/**
	 * hashmap to hold all the data about the cost of 
	 * the procedures they underwent
	 */
	private static final HashMap<String, Integer> BILLITEMS 
	= new HashMap<String, Integer>();

	static {
		BILLITEMS.put("Flu Vaccine", 25);
		BILLITEMS.put("Tetnus Vaccine", 30);
		BILLITEMS.put("MMR Vaccine", 15);
		BILLITEMS.put("Hepatitis A Vaccine", 50);
		BILLITEMS.put("Steroid Vaccine", 56);
		BILLITEMS.put("Urinalysis(BUN)", 50);
		BILLITEMS.put("Urinalysis (Drug Test)", 25);
		BILLITEMS.put("CBC", 75);
		BILLITEMS.put("Cholesterol", 40);
		BILLITEMS.put("HIV", 100);
		BILLITEMS.put("Glucose", 75);
		BILLITEMS.put("Adrenal", 65);
		BILLITEMS.put("EKG", 100);
		BILLITEMS.put("MRI", 1000);
		BILLITEMS.put("Office Base Visit", 50);
		BILLITEMS.put("Phone Consult", 35);
		BILLITEMS.put("Annual Physical", 75);
	}
	
	/**
	 * Date variable
	 */
	private long date;
	
	/**
	 * bill variable 
	 */
	private List<String> bill = new ArrayList<String>();
	
	private String billItems;
	/**
	 * The constructor for the invoice. It takes in its document Id
	 * @param docId
	 * @param patient
	 * @param doctor
	 * @param date
	 * @param bill
	 */
	public Invoice(String docId, String billItems, long date) {
		super(docId, "invoices");
		this.billItems = billItems;
		this.date = date;
		StringTokenizer st = new StringTokenizer(billItems, ";");
		while(st.hasMoreTokens()){
			bill.add(st.nextToken());
		}
		
		
	}
	
	public Invoice(String docId){
		this(docId, "", 0);
	}
	
	/**
	 * calculates the total cost according to the items in the bill
	 * @return total int.
	 */
	public int calculateTotalCost(){
		int total = 0;
		for(String s : bill) {
			total += BILLITEMS.get(s);
		}
		
		return total;
		
	}
	
	public int getItemCost(String item){
		return BILLITEMS.get(item);
	}
	
	public String getBillItems(){
		return billItems;
	}
	
	public void setBillItems(String billItems){
		this.billItems = billItems;
		this.bill = new ArrayList<String>();
		StringTokenizer st = new StringTokenizer(billItems, ";");
		while(st.hasMoreTokens()){
			bill.add(st.nextToken());
		}
	}
	
	public List<String> getBill(){
		return this.bill;
	}
	
	public void setDate(long date){
		this.date = date;
	}
	
	public long getDate(){
		return date;
	}
	

	public String[] getDataAsStrings() {
		Calendar c = Calendar.getInstance();
		c.setTimeInMillis(date);
		String[] sample = {
				"Invoice",
				(c.get(Calendar.MONTH)+1) + "/" + c.get(Calendar.DAY_OF_MONTH)
						+ "/" + c.get(Calendar.YEAR), "Total: $" + calculateTotalCost() + ".00"};
		return sample;
	}

}